#ifndef __RINGBUF_H__
#define __RINGBUF_H__

/*********************************************************************
 * INCLUDES
 */

#include "threadasync.h"

#ifdef __cplusplus
extern "C" {
#endif

/*********************************************************************
 *  EXTERNAL VARIABLES
 */

/*********************************************************************
 * MACROS
 */

/*********************************************************************
 * TYPES
 */

typedef struct _ring_buf
{
    void    *pBuffer;
    volatile uint16_t usWPos;   //Ð´Î»ÖÃ
    volatile uint16_t usRPos;   //¶ÁÎ»ÖÃ
    uint16_t usBufSize;         //»º´æ´óÐ¡
    uint16_t usElementSize;     //»º´æ±£´æµÄÔªËØ´óÐ¡
    osMutexId_t pMutexID;
} RING_BUF_S;

/*********************************************************************
 * FUNCTIONS
 */

/**
 *   @Description: »·ÐÎ»º´æ³õÊ¼»¯
 *   @param: pstRingBuf - Èë²Î£¬»º´æÍ·Ö¸Õë
 *   @param: usBufSize - Èë²Î£¬»º´æ´óÐ¡
 *   @param: usElementSize - Èë²Î£¬¶ÓÁÐ±£´æµÄÔªËØ´óÐ¡
 *   @return £º´íÎóÐÅÏ¢
 */
int32_t RB_RingBufInit(RING_BUF_S *pstRingBuf, uint16_t usBufSize, uint16_t usElementSize);

/**
 *   @Description: »·ÐÎ»º´æÏû»Ù
 *   @param: pstRingBuf - Èë²Î£¬»º´æÍ·Ö¸Õë
 *   @return £º´íÎóÐÅÏ¢
 */
int32_t RB_RingBufDestroy(RING_BUF_S *pstRingBuf);

/**
 *   @Description: »·ÐÎ»º´æÖØÖÃ£¬²»ÇåÄÚ´æ£¬»º´æ¶ÓÁÐÊý¾Ý
 *   @param: pstRingBuf - Èë²Î£¬»º´æÍ·Ö¸Õë
 *   @return £º´íÎóÐÅÏ¢
 */
int32_t RB_RingBufReset(RING_BUF_S *pstRingBuf);

/**
 *   @Description: »·ÐÎ»º´æÊÇ·ñÎª¿Õ
 *   @param: pstRingBuf - Èë²Î£¬»º´æÍ·Ö¸Õë
 *   @return £º_TRUE/_FALSE
 */
bool RB_RingBufIsEmpty(RING_BUF_S *pstRingBuf);

/**
 *   @Description: »·ÐÎ»º´æÊÇ·ñÒÑÂú
 *   @param: pstRingBuf - Èë²Î£¬»º´æÍ·Ö¸Õë
 *   @return £º_TRUE/_FALSE
 */
bool RB_RingBufIsFull(RING_BUF_S *pstRingBuf);

/**
 *   @Description: ¶Á»·ÐÎ»º´æÊý¾Ý
 *   @param: pstRingBuf - Èë²Î£¬»º´æÍ·Ö¸Õë
 *   @param: pData - ³ö²Î£¬¶Á³öÀ´µÄÊý¾Ý
 *   @return £º´íÎóÐÅÏ¢
 */
int32_t RB_RingBufPop(RING_BUF_S *pstRingBuf, void *pData);

/**
 *   @Description: Ð´»·ÐÎ»º´æÊý¾Ý
 *   @param: pstRingBuf - Èë²Î£¬»º´æÍ·Ö¸Õë
 *   @param: pData - Èë²Î£¬Òª±£´æµÄÊý¾Ý
 *   @return £º´íÎóÐÅÏ¢
 */
int32_t RB_RingBufPush(RING_BUF_S *pstRingBuf, const void *pData);

#ifdef __cplusplus
}
#endif /* end of __cplusplus */

#endif

/************************************** The End Of File **************************************/




